<template>
  <div class="components-container" v-cloak>
    <sweet-modal ref="dialog" class="dialog" :sweetModalMaxWidth="pageWidth" v-bind:blocking="true">
      <h3>{{title}}</h3>
      <div style="margin:10px 20px">
        <div class="layui-form-item" v-if="isAdd">
          <div class="layui-inline">
            <label class="layui-form-label">业务编号</label>
            <div class="layui-input-inline">
              <el-input v-model="regInfo.CHDREGNO" placeholder="请输入业务编号" @keyup.enter.native="getRegInfo">
                <el-button slot="append" icon="el-icon-search" @click="getRegInfo"></el-button>
              </el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">逝者姓名</label>
            <div class="layui-input-inline">
              <el-input v-model="regInfo.REGNAME" :readonly="!isAdd"></el-input>
            </div>
            <label class="layui-form-label">客户姓名</label>
            <div class="layui-input-inline">
              <el-input v-model="regInfo.CHDBUYNAME" :readonly="!isAdd"></el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item"  v-if="!istryAddress && chdData.CHDTYPE != 'B' && chdData.CHDTYPE">
          <div class="layui-inline">
            <label class="layui-form-label">到馆时间</label>
            <div class="layui-input-inline">
              <el-input v-model="regInfo.REGDATE" readonly></el-input>
            </div>
            <label class="layui-form-label">火化时间</label>
            <div class="layui-input-inline">
              <el-input v-model="regInfo.REGCREMATIONDATE" readonly></el-input>
            </div>
            <label class="layui-form-label">到馆天数</label>
            <div class="layui-input-inline">
                <el-input v-model="regInfo.Daoguanday" readonly></el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item" v-if="!istryAddress && chdData.CHDTYPE != 'B' && chdData.CHDTYPE">
            <label class="layui-form-label">证件号码</label>
            <div class="layui-input-inline">
              <el-input v-model="regInfo.REGCARDNO" readonly></el-input>
            </div>
            <label class="layui-form-label">户籍地址</label>
            <div class="layui-input-inline">
              <el-input v-model="regInfo.REGDETAILADDRESS" style="width:480px;" readonly></el-input>
            </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline">
              <el-input type="textarea" v-if="chdData.CHDTYPE == 'A'" v-model="regInfo.REGREMARK" style="width:770px;"></el-input>
              <el-input type="textarea" v-else v-model="regInfo.CHDDESC" style="width:770px;"></el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item" v-if="istryAddress && !IsShowCheckTakeCorpseAddress">
          <div class="layui-inline">
            <label class="layui-form-label">接尸地点</label>
            <div class="layui-input-inline">
              <el-input v-model="regInfo.REGADDRESS" style="width:740px;" readonly></el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label" v-if="!isAdd">减免类型</label>
            <div class="layui-input-inline backcolor" v-if="!isAdd">
              <el-select v-model="regInfo.REGISKEYPOINT" @change="getAllCharges">
                <el-option v-for="item in pointType" :key="item.CodeValue" :label="item.CodeName" :value="item.CodeValue">
                </el-option>
              </el-select>
            </div>
          </div>
        </div>
      </div>
      <div><el-button type="success" @click="chargeChoose">选择收费项目</el-button></div>
      <div :style="{maxHeight:maxHeight+'px'}">
        <table class="layui-table" style="border-spacing: 0;">
         <thead >
            <tr>
              <th width='60'>序号</th>
              <th width='220'>项目名称</th>
              <th>数量</th>
              <th>单价</th>
              <th>应收金额</th>
              <th>减免金额</th>
              <th v-if="!isHidden && IsUsePre">优惠金额</th>
              <th v-if="!isHidden && !IsUsePre">其他减免</th>
              <th>应缴金额</th>
              <th v-if="ISSHOWGROUP">部门名称</th>
              <th>操作</th>
            </tr>
          </thead>
          <div   id="box"  style="overflow-y: scroll;height: 300px; display: block; overflow: overlay;"  ref="scroll" >
          <tbody ref='inputs' >
            <tr class="allRow" v-for="(chl,index) in chlList">
              <td style="width:60px;">
                {{index+1}}
              </td>
              <td style="width:220px;">
                <el-select :disabled="getisModChl(chl.CHLSOURCE)" @change="chaSelect(index)" ref="select" v-model="chl.CHLCHAID" default-first-option clearable @keydown.enter.native="enterEvent(index,0)"
                  :filter-method="chaFilter" @visible-change="reset($event)" filterable>
                  <el-option v-for="item in chaList" :key="item.CHAID" :label="item.CHANAME" :value="item.CHAID" :disabled="disabled(item.CHAID)">
                  </el-option>
                </el-select>
              </td>
              <td>
                <el-input :disabled="getisModChl(chl.CHLSOURCE)" @keyup.native="check(index)" @input="moneychang(index)" @keydown.enter.native="enterEvent(index,1)" v-model="chl.CHLNUM">
                  <template v-if="chl.CHLAUNIT" slot="append">{{chl.CHLAUNIT}}</template>
                </el-input>
              </td>
              <td>
                <el-input :disabled="getisModChl(chl.CHLSOURCE)" @keyup.native="check(index)" @input="moneychang(index)" @keydown.enter.native="enterEvent(index,2)" :readonly="chl.CHALOGO === 'A'" v-model="chl.CHLMONEY">
                  <template slot="append">元</template>
                </el-input>
              </td>
              <td>
                {{chl.CHLMOUNT}}元
              </td>
              <!-- 减免金额 -->
              <td v-if="chl.CHAMODIFYJMMONEY == '' || chl.CHAMODIFYJMMONEY == null">
                {{chl.CHLREDUCTION}}元
              </td>
              <td v-if="chl.CHAMODIFYJMMONEY == 'B'">
                <el-input :disabled="getisModChl(chl.CHLSOURCE)" v-model="chl.CHLREDUCTION" @input="Jianmianchang" @keydown.enter.native="enterEvent(index,3)" @keyup.native ="chlreductionchange(index)">
                  <template slot="append">元</template>
                </el-input>
              </td>
              <!-- 优惠金额 -->
              <td v-if="!isHidden">
                <el-input :disabled="getisModChl(chl.CHLSOURCE)" @keyup.native="check(index)" @keydown.enter.native="enterEvent(index,4)" v-model="chl.CHLDISCOUNT">
                  <template slot="append">元</template>
                </el-input>
              </td>
              <td>
                {{chl.CHLRECEIVED}}元
              </td>
              <td v-if="ISSHOWGROUP">{{chl.DPTNAME}}</td>
              <td>
                <button :disabled="getisModChl(chl.CHLSOURCE)" class="layui-btn layui-btn-small layui-btn-normal" @click="remove(index)">
                  <i class="layui-icon">&#xe640;</i>
                </button>
              </td>

            </tr>

          </tbody>
          <tfoot>
            <tr>
              <td style="width:60px;">

              </td>
              <td style="width:220px;">
                <el-button v-if="isCommon()" type="primary" @click="getCommonItem">添加常用项</el-button>
              </td>
              <td>
                
              </td>
              <td>
                <span>合计</span>
              </td>
              <td :class="showclass? 'bigfont':''" style="font-weight:bold">{{ mountTotal }}元</td>
              <td :class="showclass? 'bigfont':''"  style="font-weight:bold">{{ reductionTotal }}元</td>
              <td :class="showclass? 'bigfont':''"  style="font-weight:bold" v-if="!isHidden">{{ discountTotal }}元</td>
              <td :class="showclass? 'bigfont':''"  style="font-weight:bold">{{ chlreceivedTotal }}元</td>
              <td :class="showclass? 'bigfont':''"  style="font-weight:bold" v-if="ISSHOWGROUP"></td>
              <td>
                <button class="layui-btn layui-btn-small layui-btn-normal" @click="insert()">
                  <i class="layui-icon">&#xe654;</i>
                </button>
              </td>
            </tr>
          </tfoot>
          </div>
        </table>
      </div>
      <div class="layui-form-item btnCenter sweet-btn">
        <p style="position:absolute;color:red">丧葬用品总金额：{{SZYPSubtotal}}  骨灰盒总金额：{{GHHSubtotal}}</p>
        <el-button @click="closeDialog">取消</el-button>
        <el-button type="primary" @click="openDialog()" :loading="this.$store.state.isloading">保存</el-button>
          <div class="layui-inline">
              <el-button type="primary" @click="getHistray">历史记录</el-button>
              <el-dialog title="收费信息" :visible.sync="dialogTableVisible" :modal-append-to-body="false" width="60%">
                 <el-table :data="diechdData" border fit max-height="500" style="width:100%">
                    <el-table-column property="CHLCHANAME" label="收费项目名称" align="center"></el-table-column>
                    <el-table-column property="CHLMONEY" label="单价" align="center"></el-table-column>
                    <el-table-column property="CHLNUM" label="数量" align="center"></el-table-column>
                    <el-table-column property="CHLMOUNT" label="应收金额" align="center"></el-table-column>
                    <el-table-column property="CHLREDUCTION" label="减免金额" align="center"></el-table-column>
                    <el-table-column property="CHLDISCOUNT" label="优惠金额" align="center"></el-table-column>
                    <el-table-column property="CHLRECEIVED" label="实收金额" align="center"></el-table-column>
                    <el-table-column property="CHLPRICE" label="起步价" align="center"></el-table-column>
                    <el-table-column property="CHLHIPRICE" label="最高价" align="center"></el-table-column>
                    <el-table-column property="CHLDESC" label="备注" align="center"></el-table-column>
                </el-table>
                 <span slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="dialogTableVisible = false">取 消</el-button>
                  </span>
              </el-dialog>
          </div>
      </div>
    </sweet-modal>
    <sweet-modal ref="info" class="dialog" :sweetModalMaxWidth="pageWidth" v-bind:blocking="true">
      <h3>{{title}}</h3>
      <div style="margin:10px 20px">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">逝者姓名</label>
            <div class="layui-input-inline">
              <el-input v-model="chdData.REGNAME" readonly></el-input>
            </div>
            <label class="layui-form-label">业务编号</label>
            <div class="layui-input-inline">
              <el-input v-model="chdData.REGBUSNUM" readonly></el-input>
            </div>
     
          </div>
        </div>
              <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label" v-if="!IsGovernIptDisplay">付款方式</label>
            <div class="layui-input-inline" v-if="!IsGovernIptDisplay">
              <el-input v-model="chdData.CHDCODNAME" readonly></el-input>
            </div>
            <label class="layui-form-label" v-if="!IsGovernIptDisplay">客户姓名</label>
            <div class="layui-input-inline" v-if="!IsGovernIptDisplay">
              <el-input v-model="chdData.CHDBUYNAME" readonly></el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">缴款日期</label>
            <div class="layui-input-inline">
              <el-input v-model="chdData.CHDDATE" readonly></el-input>
            </div>
            <label class="layui-form-label">缴款时间</label>
            <div class="layui-input-inline">
              <el-input v-model="chdData.CHDTIME" readonly></el-input>
            </div>
            <label class="layui-form-label">应收金额</label>
            <div class="layui-input-inline">
              <el-input v-model="chdData.CHDAMOUNT" readonly :class="showclass? 'bigfont':''" >
                <template slot="append">元</template>
              </el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">减免金额</label>
            <div class="layui-input-inline">
              <el-input v-model="chdData.CHDREDUCTION" readonly>
                <template slot="append">元</template>
              </el-input>
            </div>
            <label class="layui-form-label" v-if="!isHidden && IsUsePre">优惠金额</label>
            <label class="layui-form-label" v-if="!isHidden && !IsUsePre">其他减免</label>
            <div class="layui-input-inline" v-if="!isHidden">
              <el-input v-model="chdData.CHDDISCOUNT" readonly>
                <template slot="append">元</template>
              </el-input>
            </div>
            <label class="layui-form-label">实收金额</label>
            <div class="layui-input-inline">
              <el-input v-model="chdData.CHDRECEIVED" readonly :class="showclass? 'bigfont':''" >
                <template slot="append">元</template>
              </el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <!-- REGREMARK  regInfo.CHDDESC -->
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline">
              <el-input type="textarea" v-if="chdData.CHDTYPE == 'A'" v-model="regInfo.REGREMARK" style="width:740px;"></el-input>
              <el-input type="textarea" v-else v-model="regInfo.CHDDESC" style="width:740px;"></el-input>
            </div>
          </div>
        </div>
      </div>
      <div style="maxHeight:500px;overflow:auto;">
        <table class="layui-table" lay-even>
          <colgroup>
            <col>
            <col>
            <col>
            <col>
            <col>
            <col>
            <col>
          </colgroup>
          <thead>
            <tr>
              <th>项目名称</th>
              <th>数量</th>
              <th>单价</th>
              <th>应收金额</th>
              <th>减免金额</th>
              <th v-if="!isHidden && IsUsePre">优惠金额</th>
              <th v-if="!isHidden && !IsUsePre">其他减免</th>
              <th v-if="chdData.CHDSTATUS==='B'">实收金额</th>
              <th v-else="chdData.CHDSTATUS==='B'">应缴金额</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="(chl,index) in chlList">
              <td>{{chl.CHLCHANAME}}</td>
              <td>{{chl.CHLNUM}}{{chl.CHLAUNIT}}</td>
              <td>{{chl.CHLMONEY}}元</td>
              <td>{{chl.CHLMOUNT}}元</td>
              <td>{{chl.CHLREDUCTION}}元</td>
              <td v-if="!isHidden">{{chl.CHLDISCOUNT}}元</td>
              <td>{{chl.CHLRECEIVED}}元</td>
            </tr>
          </tbody>
          <tfoot>
            <tr>
              <td colspan="3">合计</td>
              <td :class="showclass? 'bigfont':''" style="font-weight:bold">{{ mountTotal }}元</td>
              <td :class="showclass? 'bigfont':''" style="font-weight:bold">{{ reductionTotal }}元</td>
              <td :class="showclass? 'bigfont':''"  style="font-weight:bold" v-if="!isHidden">{{ discountTotal }}元</td>
              <td :class="showclass? 'bigfont':''" style="font-weight:bold">{{ chlreceivedTotal }}元</td>
            </tr>
          </tfoot>
        </table>
      </div>
      <div class="layui-form-item btnCenter sweet-btn">
        <el-button @click="closeDialog">取消</el-button>
        <el-button type="primary" v-if="!iscopysfqd" @click="printReg()" :loading="this.$store.state.isloading">{{printName}}</el-button>
        <el-button type="primary" v-if="DisplayPrintReg" @click="printRegs()" :loading="this.$store.state.isloading">火化登记表打印</el-button>
        <el-button type="primary" v-if="(this.chdData.CHDSTATUS == 'B') && iskh && iscopysfqd" @click="printReg()" :loading="this.$store.state.isloading">{{printName}}</el-button>
      </div>
    </sweet-modal>
    <sweet-modal ref="num" class="dialog" :sweetModalMaxWidth="450" v-bind:blocking="true">
      <h3>{{title}}</h3>
      <div style="margin:10px 20px">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">逝者姓名</label>
            <div class="layui-input-inline">
              <el-input v-model="regInfo.REGNAME" disabled></el-input>
            </div>
          </div>
        </div>
      </div>
      <div style="margin:10px 20px">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">业务编号</label>
            <div class="layui-input-inline">
              <el-input v-model="regInfo.CHDREGNO" disabled></el-input>
            </div>
          </div>
        </div>
      </div>
      <div style="margin:10px 20px">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">火化编号</label>
            <div class="layui-input-inline">
              <el-input v-model="regInfo.REGCREPROVENO" oninput ="value=value.replace(/[^\d]/g,'')"></el-input>
            </div>
          </div>
        </div>
      </div>
      
      <div class="layui-form-item btnCenter sweet-btn">
        <el-button @click="closeDialog">取消</el-button>
        <el-button type="primary" @click="submit">提交</el-button>
      </div>
    </sweet-modal>
    <sweet-modal ref="checkout" class="dialog" :sweetModalMaxWidth="pageWidth" v-bind:blocking="true">
      <h3>{{title}}</h3>
      <div style="margin:10px 20px">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">逝者姓名</label>
            <div class="layui-input-inline">
              <el-input v-model="chdData.REGNAME" readonly></el-input>
            </div>
            <label class="layui-form-label">客户姓名</label>
            <div class="layui-input-inline">
              <el-input v-model="chdData.CHDBUYNAME" readonly></el-input>
            </div>
            <label class="layui-form-label">应收金额</label>
            <div class="layui-input-inline">
              <el-input v-model="chdData.CHDAMOUNT" :class="showclass? 'bigfont':''"  readonly>
                <template slot="append">元</template>
              </el-input>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">减免金额</label>
            <div class="layui-input-inline">
              <el-input v-model="chdData.CHDREDUCTION" readonly>
                <template slot="append">元</template>
              </el-input>
            </div>
            <label class="layui-form-label" v-if="!isHidden">优惠金额</label>
            <div class="layui-input-inline" v-if="!isHidden">
              <el-input v-model="chdData.CHDDISCOUNT" readonly>
                <template slot="append">元</template>
              </el-input>
            </div>
            <label class="layui-form-label">应缴金额</label>
            <div class="layui-input-inline">
              <el-input v-model="chlreceivedTotal" :class="showclass? 'bigfont':''"  readonly>
                <template slot="append">元</template>
              </el-input>
            </div>
          </div>
     
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline">
              <el-input type="textarea" v-if="chdData.CHDTYPE == 'A'" v-model="regInfo.REGREMARK" style="width:480px;"></el-input>
              <el-input type="textarea" v-else v-model="regInfo.CHDDESC" style="width:480px;"></el-input>
            </div>
          </div>
        </div>
      </div>
      <div style="maxHeight:400px;overflow:auto;">
        <table class="layui-table" lay-even>
          <colgroup>
            <col>
            <col>
            <col>
            <col>
            <col>
            <col>
            <col>
          </colgroup>
          <thead>
            <tr>
              <th>项目名称</th>
              <th>数量</th>
              <th>单价</th>
              <th>应收金额</th>
              <th>减免金额</th>
              <th v-if="!isHidden">优惠金额</th>
              <th>应缴金额</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="(chl,index) in chlList">
              <td>{{chl.CHLCHANAME}}</td>
              <td>{{chl.CHLNUM}}{{chl.CHLAUNIT}}</td>
              <td>{{chl.CHLMONEY}}元</td>
              <td>{{chl.CHLMOUNT}}元</td>
              <td>{{chl.CHLREDUCTION}}元</td>
              <td v-if="!isHidden">{{chl.CHLDISCOUNT}}元</td>
              <td>{{chl.CHLRECEIVED}}元</td>
            </tr>
          </tbody>
          <tfoot>
            <tr>
              <td colspan="3">合计</td>
              <td :class="showclass? 'bigfont':''" style="font-weight:bold">{{ mountTotal }}元</td>
              <td :class="showclass? 'bigfont':''" style="font-weight:bold">{{ reductionTotal }}元</td>
              <td :class="showclass? 'bigfont':''" style="font-weight:bold" v-if="!isHidden">{{ discountTotal }}元</td>
              <td :class="showclass? 'bigfont':''" style="font-weight:bold">{{ chlreceivedTotal }}元</td>
            </tr>
          </tfoot>
        </table>
      </div>
      <div style="margin:10px 20px">
        <div class="layui-form-item">
          <div class="layui-inline" style="height:40px;" v-if="!IsGovernIptDisplay">
            <label class="layui-form-label">付款方式</label>
            <el-radio-group v-model="payData.CHDCODNAME">
              <el-radio-button v-for="item in payment" :key="item.CodeValue" :label="item.CodeValue" class="radio">{{item.CodeName}}</el-radio-button>
            </el-radio-group>
          </div>

          <div class="layui-inline">
            <label class="layui-form-label">结账日期</label>
            <div class="layui-input-inline">
              <el-date-picker v-date type="date" placeholder="选择日期" v-model="CHECKOUTTIME"  format="yyyy-MM-dd"></el-date-picker>
            </div>
          </div>
        </div>
        <div class="layui-form-item" v-if="!IsGovernIptDisplay">
          <div class="layui-inline">
            <label class="layui-form-label">发票抬头</label>
            <div class="layui-input-inline">
              <el-input v-model="payData.CHDPAYTITLE"></el-input>
            </div>
            <label class="layui-form-label">税号</label>
            <div class="layui-input-inline">
              <el-input v-model="payData.CHDPAYSH"></el-input>
            </div>
          </div>
        </div>
      </div>
      <div class="layui-form-item btnCenter sweet-btn">
        <el-button @click="closeDialog">取消</el-button>
        <el-button type="primary" :loading="this.$store.state.isloading" @click="submit">结账</el-button>
        <el-button v-if="iscopysfqd && ischeck1" type="primary" @click="PrintingSFQD">打印收费清单</el-button>
        <el-button v-if="iscopysfqd && ischeck2" type="primary" @click="PrintingLSQD">打印零售清单</el-button>
        <el-button v-if="isshowInvoice && printInvoice" type="primary" @click="Printingfp">打印发票</el-button>
        <el-button v-show="IsShowHangAccount" type="primary" :loading="this.$store.state.isloading" @click="hangAccount">挂账</el-button>
      </div>
    </sweet-modal>
    <sweet-modal ref="print" class="dialog" :sweetModalMaxWidth="pageWidth">
      <h3>{{ printTitle }}</h3>
      <iframe :src="printUrl" style="width:1100px; height:500px;margin-top:20px;"></iframe>
    </sweet-modal>
    <chargeChoose ref="chargeChoose" @makeSure="makeSure"></chargeChoose>  
  </div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
  @import "src/styles/common.scss";
  .bigfont{
    font-size: 18px;
    font-weight: 800;
    color:black;
  }
  .layui-table tr{
    display: table;
    -moz-display: table;
    width: 100%;
    table-layout: fixed;
  }
  .el-button+.el-button {
    margin-left: 0;
  }

  .sweet-btn {
    margin-top: 20px;
  }
  .el-select-dropdown__item.hover, .el-select-dropdown__item:hover {
    background-color: yellow;
  }
 
</style>

<script>
  import sweetModal from "@/components/sweetModal";
  import chargeChoose from "@/components/chargeChoose/chooseCharge";
  import apiBase from "@/api/apiBase.js";
  import { formatDate, timeStringToDate, DateDiff,formatDateString } from "@/utils/date.js";
  import {
    accMul,
    Subtr,
    accAdd
  } from "@/utils/operations.js";
  import {
    ORDER
  } from "@/const/orderConst.js";
  import axios from 'axios'
  const MANUAL = "A";
  const AUTO = "B";

  export default {
    name: "hello",
    data() {
      return {
        showclass:null,
        isshow:null,
        piao:"",
        CHECKOUTTIME:new Date(),
        personality: null,
        pageWidth: 1200,
        maxHeight: 500,
        CHDID: null,
        order: null,
        title: null,
        //所有收费项目
        allCharge: [],
        allCharges: [],
        chaList: [],
        payment: [],
        pointType: [],
        payData: {
          CHDCODNAME:'现金'
        },
        printUrl: null,
        printTitle: null,
        isHidden: null,
        //收费信息
        chdData: {},
        diechdData:[],
        dialogTableVisible:false,
        regInfo: {
          CHDREGNO: null,
          CHDREGID: null,
          REGNAME: null,
          // CHDREGNAME: null,
          CHDDEADNAME: null,
          CHDBUYNAME: null,
          REGCREMATIONDATE: null,
          REGDATE: null,
          Daoguanday: null,
          CHDDESC: null,
          REGADDRESS: null,
          REGDETAILADDRESS: null,//户籍地址
          REGCARDNO: null,//证件号码
          REGISKEYPOINT: null,
          REGYITIQX: null,
          REGGHQX: null,
          REGREMARK: null,
          REGCREPROVENO: null, // 火化编号
        },
        //打印类型
        printName:null,
        //收费项目
        chlList: [],
        chl: {
          CHLID: "",
          CHLCHAID: "", //收费项目ID（必传）
          CHLCHANAME: "", //收费项目名称（必传）
          CHLMOUNT: 0, //应缴金额（必传）
          CHLPRICE: null, //起步价
          CHLHIPRICE: null, //最高价
          CHLMONEY: 0, //单价
          CHLNUM: 1, //数量
          CHLAUNIT: null, //计量单位
          CHLREDUCTION: 0, //减免金额
          CHLDISCOUNT: 0, //优惠金额
          CHLDESC: null, //备注
          CHLRECEIVED: 0,
          CHAMODIFYJMMONEY: '',
          CHLFROMLOGO: MANUAL //来源标记
        },
        isshow: null,
        // 是否显示挂账按钮
        IsShowHangAccount: null,
        // 是否把优惠金额改成其他减免
        IsUsePre: null,
        iskh: true,
        iscopysfqd: null,
        ISSHOWGROUP: null,
        ischeck1: null, //判断来源是结账还是零售结账 1是结账 2是零售结账
        ischeck2: null, //判断来源是结账还是零售结账 1是结账 2是零售结账
        istryAddress: null,
        OnlyQueryBusiness: null,
        IsUseAccurateQuery: null,
        IsPricingSubtotal: null,
        GHHSubtotal: null,
        SZYPSubtotal: null,
        IsGovernIptDisplay: null,
        NullandB: false,
        isshowInvoice: false,
        printInvoice: null,
        DisplayPrintReg: null,
        IsShowCheckTakeCorpseAddress: null, //调整收费项目不显示接尸地点（嵊州）
        REGCURSTATUS: null,
        isModChl: null, // 是否可以修改其他来源收费（flase可修改，true 不可修改）
        isUseNewApiByRetail: null, // 零售收费编号查询逝者信息是否调用新接口(true 根据来源  false 不根据来源)
        chackprice:[],// 实收限价
      };
    },
    methods: {
      // 选择收费项目
      chargeChoose(){
        this.$refs.chargeChoose.open('选择收费项目',this.chlList)
      },
      // 弹出选择收费的弹框，确认选中
      makeSure(val){
        let arr = val.map(item=>{
          let cha = this.getChaByID(item.CHAID);
          //初始化chl
          if (cha) {
            let chl = {
              CHALOGO : cha.CHALOGO,
              CHLCHAID: cha.CHAID,
              CHLCHANAME : cha.CHANAME,
              CHLAUNIT : cha.CHAAUNIT,
              CHLMONEY : cha.CHAMONEY,
              CHLNUM : 1,
              CHLMOUNT : cha.CHAMONEY,
              CHLREDUCTION : cha.CHAJMMONEY,
              CHLDISCOUNT : cha.CHADISCOUNT,
              CHLRECEIVED : cha.CHAMONEY - cha.CHAJMMONEY - cha.CHADISCOUNT,
              CHAMODIFYJMMONEY : cha.CHAMODIFYJMMONEY,
            };
            return chl
          }
        })
        if(this.chlList.length>0){
          if(this.chlList[this.chlList.length-1].CHLCHAID == ''){
            this.chlList.splice(this.chlList.length - 1, 1);
          }
        }
        this.chlList = this.chlList.concat(arr)
        this.insert()
      },
      // 判断调整收费项目是否可以修改（根据来源和参数isModChl）
      getisModChl(val){
        return this.isModChl && Boolean(val)
      },
      // 挂账
      hangAccount() {
        this.$confirm("确认是否挂账?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
        .then(callback => {
          let data = {
            CHDID: this.CHDID
          };
          apiBase.DoService(data, apiBase.getApiAdress().Checkout.Bill, res => {
            this.$message({
              type: "success",
              message: "挂账成功!"
            });
            this.closeDialog();
            this.refreshData();
            apiBase.DoService(
            data, 
            apiBase.getApiAdress().Pdf.PrintReg,
            res => {
              this.printUrl = res.data.content.PDFNAME;
              this.printTitle = "挂账费用清单打印";
              this.$refs.print.open();
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
      },
      //个性化是否隐藏优惠金额
      getParam() {
        let data = {};
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Param.GetIsHidePreferential,
          res => {
            this.isHidden = res.data.content;
          }
        );
        apiBase.DoService(data, apiBase.getApiAdress().Param.GetIsShowHangAccount, res => {
          this.IsShowHangAccount = res.data.content;
        });
      },
      //获取逝者收费信息
      getHistray(){
        this.diechdData = []
        this.dialogTableVisible = true
        if(this.regInfo.CHDREGID == null){
          // console.log('没有编号');
        }else{
          let data = {REGID:this.regInfo.CHDREGID};
          apiBase.DoService(
          data,
          apiBase.getApiAdress().Checkout.GetAllChdByReg,
          res => {
            this.diechdData = res.data.content;
            for(let index in this.diechdData){
              this.diechdData[index].CHLNUM = this.diechdData[index].CHLNUM + this.diechdData[index].CHLAUNIT;
              this.diechdData[index].CHLDISCOUNT = this.diechdData[index].CHLDISCOUNT + '元';
              this.diechdData[index].CHLHIPRICE = this.diechdData[index].CHLHIPRICE + '元';
              this.diechdData[index].CHLMONEY = this.diechdData[index].CHLMONEY + '元';
              this.diechdData[index].CHLMOUNT = this.diechdData[index].CHLMOUNT + '元';
              this.diechdData[index].CHLPRICE = this.diechdData[index].CHLPRICE + '元';
              this.diechdData[index].CHLRECEIVED = this.diechdData[index].CHLRECEIVED + '元';
              this.diechdData[index].CHLREDUCTION = this.diechdData[index].CHLREDUCTION + '元';
            }
          }
         )
        }
        
      },
      //获取付款方式
      getPayment() {
        let data = {};
        apiBase.DoService(data, apiBase.getApiAdress().Code.GetPayment, res => {
          this.payment = res.data.content;
        });
      },
      //获取减免类型
      getPointType() {
        let data = {};
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Code.GetKeyPointType,
          res => {
            this.pointType = res.data.content;
            console.log(this.regInfo.REGISKEYPOINT)
            if(this.regInfo.REGISKEYPOINT==null){
              this.regInfo.REGISKEYPOINT=this.pointType[0]
            }
          }
        );
      },
      //下载txt 发票 （宁波）
      downloadWithBlob(txt) {
        axios({
            url: "http://127.0.0.1:8080/",
            method: "POST",
            data: { data: txt },
            headers: { "Content-Type": "text/plain" }
          })
            .then(res => {
              if (res.data.Success) {
              console.log("生成文件成功!");
              } else {
                console.log(res.data.ErrMsg);
              }
            })
        },
      //结账
      chdCheckout() {
        let _this = this;
        this.payData.CHDID = this.CHDID;
        let data = JSON.parse(JSON.stringify(this.payData));
        data.CHDDATE = formatDate(this.CHECKOUTTIME, "yyyyMMdd");
        apiBase.DoService(data, apiBase.getApiAdress().Checkout.Checkout, res => {
            if(res.data.content.strReturn){
            this.piao=res.data.content.strReturn;
            }
            this.REGCURSTATUS = res.data.content.REGCURSTATUS;
            this.$message({
            type: "success",
            message: "结账成功!"
          });
          if(res.data.msg == '成功'){
            if(this.piao){
            this.downloadWithBlob(this.piao);　　// 调用成功
            }
            this.isshowInvoice = true;//结账成功，临海要显示打印发票的按钮
            if (this.order === ORDER.CHECKOUT) {
            let data = {};
              apiBase.DoService(
                data, 
                apiBase.getApiAdress().Param.GetCheckoutReport,
                res => {
                  this.personality = res.data.content;
                  if(this.personality == '20'){
                    this.printName = "收费清单打印";
                    this.printReg();//打印
                  }else if(this.personality == '10'){
                    this.printName = "火化登记表打印";
                    this.printReg();//打印
                  }else if(this.personality == '40'){
                    if(this.REGCURSTATUS != 'E'){
                      this.printName = "打印火化证明单";
                      this.printReg();//打印
                    }
                  }else if(this.personality == '50'){
                    this.printName = "打印减免清单";
                    this.printReg();//打印
                  }
                });
            }else if(this.order === ORDER.RETCHECKOUT){
              apiBase.DoService(
                {}, 
                apiBase.getApiAdress().Param.GetCheckoutReport,
                res => {
                  if(res.data.content == '10'){
                    this.printName = "零售清单打印"
                    this.printReg();
                  }
                });
            }
          }
          if(this.printInvoice == false){
              this.closeDialog();
          };
          this.refreshData();
        },
        res => {
            this.$message.error(res.data.msg);
        });
      },
      PrintingSFQD(){
        this.printName = "收费清单打印"
        this.printReg();
      },
      PrintingLSQD() {
        this.printName = "零售清单打印"
        this.printReg();
      },
      Printingfp(){
        this.printName = "发票打印"
        this.printReg();
      },
      //单纯的获取下拉框中的收费项目
      getXialaData(){
        return new Promise((resolve,reject)=>{
          let data = {
            Data: {
              REGISKEYPOINT: this.regInfo.REGISKEYPOINT
            }
          };
          apiBase.DoService(
            data,
            apiBase.getApiAdress().Checkout.GetAllCharge,
            res => {
              this.allCharge = res.data.content.OutData; //保存的是所有的收费项目
              if(this.OnlyQueryBusiness){
                this.allCharge.forEach(item => {   //个性化需求，一些馆在收费项目中只显示实体物品  放在chalist（下拉中真实显示的收费项目）
                  if(item.CYPTYPE == 'B'){
                    this.chaList.push(item);
                  }
                });
                resolve();
              }else{
                this.chaList = JSON.parse(JSON.stringify(this.allCharge));
                resolve();
              }
            }
          );
        })

      },
      //获取收费项目并且重新计算每一行的数据
      getAllCharge() {
        let data = {
          Data: {
            REGISKEYPOINT: this.regInfo.REGISKEYPOINT
          }
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Checkout.GetAllCharge,
          res => {
            this.allCharge = res.data.content.OutData; //保存的是所有的收费项目
            if(this.OnlyQueryBusiness){
              this.allCharge.forEach(item => {   //个性化需求，一些馆在收费项目中只显示实体物品  放在chalist（下拉中真实显示的收费项目）
                if(item.CYPTYPE == 'B'){
                  this.chaList.push(item);
                }
              });
            }else{
              this.chaList = JSON.parse(JSON.stringify(this.allCharge));
            }
            for (var index in this.chlList) {  // chllist  保存的是该逝者所有的收费项目
              this.chlCompute(index); //计算每一行的数据
            }
          }
        );
      },
      //收费项目
      getAllChargees() {
        let data = {
          Data: {
            REGISKEYPOINT: this.regInfo.REGISKEYPOINT
          }
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Checkout.GetAllCharges,
          res => {
            this.allCharges = res.data.content.OutData;  
          }
        );
      },
      async getAllCharges(){
        await this.queryRtfByReliefType()
        for (let chl of this.chlList) {
          let chackpriceItem = this.chackprice.filter((item)=>{
            return chl.CHLCHAID == item.RTFCHAID
          })
          if(chackpriceItem.length){
            var chlmount = accMul(chl.CHLMONEY, chl.CHLNUM);
            chl.CHLREDUCTION = 0;
            chl.CHLMOUNT = chlmount
            if(chlmount<chackpriceItem[0].RTFSTARTAMOUNT){
              chl.CHLRECEIVED = chackpriceItem[0].RTFSTARTAMOUNT
            }else if(chlmount>chackpriceItem[0].RTFHIGHESTAMOUNT){
              chl.CHLRECEIVED = chackpriceItem[0].RTFHIGHESTAMOUNT
              chl.CHLREDUCTION = chlmount - chl.CHLRECEIVED
            }
            return
          }
        }
        this.getAllCharge();
        this.getCommonItem(); //获取常用项
      },
      //收费详情
      dataInfo() {
        return new Promise((resolve,reject)=>{
          let data = {
            CHDID: this.CHDID
          };
          apiBase.DoService(data, apiBase.getApiAdress().Checkout.Detail, res => {   
            this.chdData = res.data.content;
            this.GHHSubtotal = res.data.content.GHHSubtotal;
            this.SZYPSubtotal = res.data.content.SZYPSubtotal;
            if(this.chdData.CHDTYPE === "A"){
              this.regInfo.REGNAME = this.chdData.REGNAME;
              this.chdData.REGNAME = this.chdData.REGNAME;
            }else if(this.chdData.CHDTYPE === "B"){
              if(this.chdData.CHDDEADNAME){
                this.regInfo.REGNAME = this.chdData.CHDDEADNAME;
                this.chdData.REGNAME = this.chdData.CHDDEADNAME;
              }else{
                this.regInfo.REGNAME = this.chdData.REGNAME;
                this.chdData.REGNAME = this.chdData.REGNAME;
              }
            };
            this.regInfo.REGCREPROVENO = this.chdData.REGCREPROVENO;
            this.regInfo.CHDREGNO = this.chdData.REGBUSNUM; //编号
            this.regInfo.CHDBUYNAME = this.chdData.CHDBUYNAME;   //客户姓名  
            this.regInfo.CHDDESC = this.chdData.CHDDESC; // 收费备注
            this.regInfo.REGREMARK = this.chdData.REGREMARK; // 逝者备注
            this.regInfo.CHDREGID = this.chdData.CHDREGID;
            this.regInfo.REGCREMATIONDATE = this.chdData.REGCREMATIONDATE;
            this.regInfo.REGDATE = this.chdData.REGDATE;
            this.regInfo.REGISKEYPOINT = this.chdData.REGISKEYPOINT;  //减免类型
            if(this.regInfo.REGISKEYPOINT=="") {
              this.regInfo.REGISKEYPOINT = 'A';  //默认减免类型
            }
            //4-15李和陈讨论后改的 注释掉了远了的 this.getRegAddress();
            this.regInfo.REGADDRESS = res.data.content.REGADDRESS;// 接尸地址
            this.regInfo.REGDETAILADDRESS = res.data.content.REGDETAILADDRESS;// 户籍地址
            this.regInfo.REGCARDNO = res.data.content.REGCARDNO; // 证件号码
            this.regInfo.REGYITIQX = res.data.content.REGYITIQX; //a 登记类型 A:火化登记,B:冷藏登记,C:灵堂登记,D:悼念厅登记
            this.regInfo.REGGHQX = res.data.content.REGGHQX; //a 逝者骨灰去向  A：直接领走 B：寄存 C：其他 D：埋葬
             //义乌算到馆时间修改过后
            if(this.regInfo.REGCREMATIONDATE != '' && this.regInfo.REGDATE != ''){  
              //有可能带时间
                 var datanotime = this.regInfo.REGCREMATIONDATE.substr(0,10)   //存在后面有空值情况
                 this.regInfo.Daoguanday = DateDiff(datanotime,this.regInfo.REGDATE);   //到馆天数 
            }else if(this.regInfo.REGCREMATIONDATE == ''){
               var todaydata=formatDateString(formatDate(new Date, "yyyyMMdd"))
               this.regInfo.Daoguanday = DateDiff(todaydata,this.regInfo.REGDATE);   //到馆天数   
            }
            // if (this.regInfo.CHDREGNO) {
            //   this.getRegAddress();
            // }
            this.chlList = this.chdData.List_Chl;
            if (
              this.order != ORDER.INFO &&
              this.order != ORDER.CHECKOUT &&
              this.order != ORDER.RETCHECKOUT&&
              this.order != ORDER.RETAILINFO
            ) {
              this.insert();
            }
            for (let chl of this.chlList) {                           
              if (!this.chaList.some(item => {
                  return item.CHAID === chl.CHLCHAID;
                }))
                this.chaList.push({
                  CHANAME: chl.CHLCHANAME,
                  CHAID: chl.CHLCHAID
                });
            } 
            resolve();
          });
        })

      },
      //修改收费项目
      dataModify(checkout = false) {
        let chlList = JSON.parse(JSON.stringify(this.chlList));
        chlList = chlList.filter(item => {
          return item.CHLCHAID && item.CHLCHAID.length > 0;
        });
        let data = {
          CHDID: this.CHDID,
          CHDREGID: this.regInfo.CHDREGID,
          CHDBUYNAME: this.regInfo.CHDBUYNAME,
          CHDDEADNAME: this.regInfo.CHDDEADNAME,
          CHDDESC: this.regInfo.CHDDESC,
          CHDTYPE: this.chdData.CHDTYPE,
          REGREMARK: this.regInfo.REGREMARK,
          REGISKEYPOINT: this.regInfo.REGISKEYPOINT
        };
      
        for(var i = 0; i < chlList.length; i++){
          for(var s = 0; s < this.chaList.length; s++){
            if(chlList[i].CHLCHAID === this.chaList[s].CHAID){
              chlList[i].CHLCHANAME = this.chaList[s].CHANAME;
            }
          }
        }
        if (chlList.length > 0) {
          data.List_Chl = chlList;
        }
        apiBase.DoService(data, apiBase.getApiAdress().Checkout.Modify, res => {
          this.$message({
            type: "success",
            message: "保存成功!"
          });
          this.closeDialog();
          this.refreshData();
          if (checkout) {
            if (this.order === ORDER.RETMODIFY) {//零售项目调整
              this.open(ORDER.RETCHECKOUT, this.CHDID, '2');
            } else {
              this.open(ORDER.CHECKOUT, this.CHDID, '1');
            }
          } else if (this.order === ORDER.CHEMODIFY) {//收费项目调整
            this.open(ORDER.INFO, this.CHDID, '1');
          }
        },
        res => {
            this.$message.error(res.data.msg);
        });
      },
      //根据正式业务编号获取地址
      getRegAddress() {
        if(this.regInfo.CHDREGNO!=null){
          let data = {
            REGNO: this.regInfo.CHDREGNO
          };
          apiBase.DoService(
            data,
            apiBase.getApiAdress().Registration.GetRegistrationByNo,
            res => {
              let reg = res.data.content;
              this.regInfo.REGADDRESS = reg.REGADDRESS;// 接尸地址
              this.regInfo.REGDETAILADDRESS = reg.REGDETAILADDRESS;// 户籍地址
              this.regInfo.REGCARDNO = reg.REGCARDNO; // 证件号码
              this.regInfo.REGISKEYPOINT = reg.REGISKEYPOINT; //减免类型
              this.regInfo.REGYITIQX = reg.REGYITIQX; //a 登记类型 A:火化登记,B:冷藏登记,C:灵堂登记,D:悼念厅登记
              this.regInfo.REGGHQX = reg.REGGHQX; //a 逝者骨灰去向  A：直接领走 B：寄存 C：其他 D：埋葬
              if(!this.regInfo.CHDDESC){
                this.regInfo.CHDDESC = reg.REGREMARK; //备注
              }
              this.regInfo.REGDATE = reg.REGDATE;       
              this.regInfo.REGCREMATIONDATE =  reg.REGCREMATIONDATE; 
                //义乌算到馆时间修改过后
                if(this.regInfo.REGCREMATIONDATE != '' && this.regInfo.REGDATE != ''){  
                    //有可能带时间
                    var datanotime = this.regInfo.REGCREMATIONDATE.substr(0,10)   //存在后面有空值情况
                    this.regInfo.Daoguanday = DateDiff(datanotime,this.regInfo.REGDATE);   //到馆天数 
                }else if(this.regInfo.REGCREMATIONDATE == ''){
                  var todaydata=formatDateString(formatDate(new Date, "yyyyMMdd"))
                  this.regInfo.Daoguanday = DateDiff(todaydata,this.regInfo.REGDATE);   //到馆天数   
                }
            }
          );
        }
      },
      //根据正式业务编号获取ID
      getRegInfo() {
        this.regInfo.CHDDESC = null;
        if(this.regInfo.CHDREGNO!=null){
        let data = {
          REGNO: this.regInfo.CHDREGNO
        };
        let url = apiBase.getApiAdress().Registration.GetRegistrationByNo;
        // 义乌 零售关联逝者 个性化接口
        if(this.isUseNewApiByRetail){
          data.REGBUSNUM = this.regInfo.CHDREGNO,
          url = apiBase.getApiAdress().Registration.GetRegistrationByNoAnAndSource
        }
        apiBase.DoService(
          data,
          url,
          res => {
            let reg = res.data.content;
            if(!reg)
            {
              this.$message({
              type: "error",
              message: "未找到逝者信息!"
              });
              Object.assign(
                this.$data.regInfo,
                this.$options.data().regInfo
                );
              return;
            }
            this.regInfo.CHDREGID = reg.REGID;
            this.regInfo.REGNAME = reg.REGNAME; //逝者姓名
            this.regInfo.CHDBUYNAME = reg.REGHANDLERNAME; //客户姓名
            this.regInfo.REGADDRESS = reg.REGADDRESS; //接尸地址
            this.regInfo.REGDETAILADDRESS = reg.REGDETAILADDRESS; //户籍地址
            this.regInfo.REGCARDNO = reg.REGCARDNO; //证件号码
            this.regInfo.REGISKEYPOINT = reg.REGISKEYPOINT; //减免类型
            this.regInfo.CHDDESC = reg.REGREMARK; // 备注
            if(this.isUseNewApiByRetail){
              this.regInfo.CHDDESC = reg.CHDDESC // 备注
              this.chlList = reg.list_Chl || []
              this.chlList.forEach((chl)=>{
                if(!this.chaList.some((cha)=>{
                  return chl.CHLCHAID == cha.CHAID
                })){
                  this.chaList = this.chaList.concat(this.allCharge.filter((cha)=>{
                    return chl.CHLCHAID == cha.CHAID
                  }))
                }
              })
              this.insert()
            }
            this.regInfo.REGDATE = reg.REGDATE;       
            this.regInfo.REGCREMATIONDATE =  reg.REGCREMATIONDATE; 
            //义乌算到馆时间修改过后
            if(this.regInfo.REGCREMATIONDATE != '' && this.regInfo.REGDATE != ''){  
              //有可能带时间
              var datanotime = this.regInfo.REGCREMATIONDATE.substr(0,10)   //存在后面有空值情况
              this.regInfo.Daoguanday = DateDiff(datanotime,this.regInfo.REGDATE);   //到馆天数 
            }else if(this.regInfo.REGCREMATIONDATE == ''){
              var todaydata=formatDateString(formatDate(new Date, "yyyyMMdd"))
              this.regInfo.Daoguanday = DateDiff(todaydata,this.regInfo.REGDATE);   //到馆天数   
            }
          }
        );
        }
      },
      // 续存根据正式业务编号获取ID
      renewGetRegInfo() {
        this.regInfo.CHDDESC = null;
        if(this.regInfo.CHDREGNO!=null){
        let data = {
          REGNO: this.regInfo.CHDREGNO,
        };
        let url = apiBase.getApiAdress().Registration.GetRegistrationByNo
        if(this.isUseNewApiByRetail){
          data.REGBUSNUM = this.regInfo.CHDREGNO,
          data.CHDSOURCE = '寄存费用'
          url = apiBase.getApiAdress().Registration.GetRegistrationByNoAnAndSource
        }
        apiBase.DoService(
          data,
          url,
          res => {
            let reg = res.data.content;
            if(!reg)
            {
              this.$message({
              type: "error",
              message: "未找到逝者信息!"
              });
              Object.assign(
                this.$data.regInfo,
                this.$options.data().regInfo
                );
              return;
            }
            if(this.isUseNewApiByRetail){
              this.chlList = res.data.content.list_Chl || []
            }
            this.regInfo.CHDREGID = reg.REGID;
            this.regInfo.REGNAME = reg.REGNAME; //逝者姓名
            this.regInfo.CHDBUYNAME = reg.REGHANDLERNAME; //客户姓名
            this.regInfo.REGADDRESS = reg.REGADDRESS; //接尸地址
            this.regInfo.REGDETAILADDRESS = reg.REGDETAILADDRESS; //户籍地址
            this.regInfo.REGCARDNO = reg.REGCARDNO; //证件号码
            this.regInfo.REGISKEYPOINT = reg.REGISKEYPOINT; //减免类型
             if(!this.regInfo.CHDDESC){
              this.regInfo.CHDDESC = reg.REGREMARK; //备注
            }
            this.regInfo.REGDATE = reg.REGDATE;       
            this.regInfo.REGCREMATIONDATE =  reg.REGCREMATIONDATE; 
                //义乌算到馆时间修改过后
                if(this.regInfo.REGCREMATIONDATE != '' && this.regInfo.REGDATE != ''){  
                  //有可能带时间
                  var datanotime = this.regInfo.REGCREMATIONDATE.substr(0,10)   //存在后面有空值情况
                  this.regInfo.Daoguanday = DateDiff(datanotime,this.regInfo.REGDATE);   //到馆天数 
                }else if(this.regInfo.REGCREMATIONDATE == ''){
                  var todaydata=formatDateString(formatDate(new Date, "yyyyMMdd"))
                  this.regInfo.Daoguanday = DateDiff(todaydata,this.regInfo.REGDATE);   //到馆天数   
                }
          }
        );
        }
      },
      //新增零售
      dataAdd(checkout = false) {
        let chlList = JSON.parse(JSON.stringify(this.chlList));
        chlList = chlList.filter(item => {
          return item.CHLCHAID && item.CHLCHAID.length > 0;
        });
        let data = JSON.parse(JSON.stringify(this.regInfo));
        if (chlList.length > 0) {
          data.List_Chl = chlList;
        }
        data.CHDDEADNAME = this.regInfo.REGNAME;
        apiBase.DoService(data, apiBase.getApiAdress().Checkout.Create, res => {
          this.$message({
            type: "success",
            message: "保存成功!"
          });
          this.closeDialog();
          this.refreshData();
          if (checkout) {
            this.open(ORDER.RETCHECKOUT, res.data.content.CHDID,'2');
          }
        },
        res => {
            this.$message.error(res.data.msg);
        });
      },
      printReduction() {
        let data = {
          CHDID: this.CHDID
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Pdf.PrintReduction,
          res => {
            this.printUrl = res.data.content;
            this.printTitle = "减免申请表打印";
            this.$refs.print.open();
          }
        );
      },
      printRegs(){
        let data = {
          CHDID: this.CHDID
        };
        apiBase.DoService(data, apiBase.getApiAdress().Pdf.PrintReg, res => {
          this.printUrl = res.data.content.PDFNAME;
          this.printTitle = "火化登记表打印";
          this.$refs.print.open();
        });
      },
      printReg() {
        if(this.printName == "火化登记表打印"){
          let data = {
            CHDID: this.CHDID
          };
          apiBase.DoService(data, apiBase.getApiAdress().Pdf.PrintReg, res => {
            this.printUrl = res.data.content.PDFNAME;
            this.printTitle = "火化登记表打印";
            this.$refs.print.open();
          });
        }else if(this.printName == "零售清单打印"){
          let data = {
            CHDID: this.CHDID
          };
          apiBase.DoService(data, apiBase.getApiAdress().Pdf.PrintRetailchargelist, res => {
            this.printUrl = res.data.content.PDFNAME;
            this.printTitle = "零售清单打印";
            this.$refs.print.open();
          });
        }else if(this.printName == "收费清单打印"){
          let data = {
            CHDID:this.CHDID
          };
          apiBase.DoService(
            data, 
            apiBase.getApiAdress().Pdf.PrintRegList,
            res => {
              this.printUrl = res.data.content.PDFNAME;
              this.printTitle = "收费清单打印";
              this.$refs.print.open();
            });
        }else if(this.printName == "打印火化证明单"){
          let data = {
            REGID:this.regInfo.CHDREGID
          };
          apiBase.DoService(
            data, 
            apiBase.getApiAdress().Pdf.UpdatePrintCre,
            res => {
              this.printUrl = res.data.content.PDFNAME;
              this.printTitle = "打印火化证明单";
              this.$refs.print.open();
            });
        }else if(this.printName == "打印减免清单"){
          let data = {
            CHDID: this.CHDID
          };
          apiBase.DoService(data, apiBase.getApiAdress().Pdf.PrintReduDetail, res => {
            this.printUrl = res.data.content.PDFNAME;
            this.printTitle = "打印减免清单";
            this.$refs.print.open();
          });
        }else if(this.printName == '发票打印'){
          let data = {
            CHDID: this.CHDID
          };
          apiBase.DoService(data, apiBase.getApiAdress().Pdf.PrintRetailInvoice, res => {
            this.printUrl = res.data.content.PDFNAME;
            this.printTitle = "发票打印";
            this.$refs.print.open();
          });
        }else{
          console.log('打印出错了');
        }
        
      },
      //新增行
      insert() {
        if(this.chlList.length == 0){
          this.chlList.push(JSON.parse(JSON.stringify(this.chl)));
        }else{
          for (let index in this.chlList) {
            let chl = this.chlList[index];
            // console.log(111);
            // console.log(chl.CHLCHAID == "");
            if (chl.CHLCHAID == "") {
              this.$message({
                type: "error",
                message: `第${parseInt(index) + 1}行收费项目不能为空!`
              });
              return false;
            }
          }
          this.chlList.push(JSON.parse(JSON.stringify(this.chl)));
        }
        
        setTimeout(() => {
            let tableHeight = this.$refs.scroll.scrollHeight;
            $("#box").animate({scrollTop:tableHeight},500);
        }, 100);
        return true;
      },
      remove(index) {
        if(this.istryAddress){
          this.$confirm("是否删除该收费?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
          .then(() => {
            this.chlList.splice(index, 1);
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消"
            });
          });
          }else{
          this.chlList.splice(index, 1);
        }
        
      },
      //回车事件
      enterEvent(rowNum, colNum) {
        //获取所有行
        let rows = this.$refs.inputs.getElementsByClassName("allRow");
        //获取当前行
        let currow = rows[rowNum];
        // 获取当前行所有列
        let inputs = currow.getElementsByTagName("input");
        //强制隐藏下拉框
        if (colNum === 0) {
          let chl = this.chlList[rowNum];
          // if(this.chaList.length != 0){
          //   chl.CHLCHAID = this.chaList[0].CHAID;
          // }
          // this.$refs.select.$el.click();
          if (chl.CHLCHAID.length === 0) {
            this.$message({
              type: "error",
              message: `第${parseInt(rowNum) + 1}行收费项目不能为空!`
            });
            return;
          }
          let select = this.$refs.select;
          select[rowNum].visible = false;
        }
        //最后一列
        if (colNum === inputs.length - 1) {
          //最后一行
          if (rowNum === this.chlList.length - 1) {
            //插入空行
            if (!this.insert()) {
              return;
            }
          }
          //换行
          this.$nextTick(function () {
          this.enterEvent(rowNum + 1, -1);
          });
        } else {
          //获取下一个焦点
          this.$nextTick(function () {
            inputs[colNum + 1].select();
            if(colNum == -1){
              let selects = this.$refs.select;
              selects[rowNum].visible = true;
            }
            
          });
        }
      },
      //禁用已选项
      disabled(chaID) {
        let retVal = this.chlList.some(item => {
          return item.CHLCHAID === chaID;
        });
        return retVal;
      },
      //打开弹出框
      async open(order, id, type) {
        this.getParam();//个性化是否隐藏优惠金额
        this.getPointType();//获取减免类型的下拉
        this.isshowGroups(); //个性化参数
        this.iscopysfqds(); //个性化参数
        this.ChargeOnlyQueryBusiness(); //个性化物品下拉   义乌下拉只有服务类，其他馆是全部数据
        this.GetIsUseAccurateQuery();  //个性化是否结账中精确查找   义乌true 其他false
        // Object.assign(this.$data, this.$options.data());
        this.CHDID = id;
        this.order = order;
        this.chlList = [];
        switch (this.order) {
          case ORDER.ADD:
            this.title = "新增零售";
            this.chlList = [];
            Object.assign(this.$data.regInfo, this.$options.data().regInfo);
            await this.getXialaData(); //获取收费项目下拉框数据
            this.insert();
            this.$refs.dialog.open();
            break;
          case '续存':
            this.title = "新增零售";
            this.chlList = [];
            Object.assign(this.$data.regInfo, this.$options.data().regInfo);
            this.getXialaData(); //获取收费项目下拉框数据
            this.insert();
            this.$refs.dialog.open();
            this.regInfo.CHDREGNO = id;
            this.renewGetRegInfo();
            break;
          case ORDER.CHEMODIFY:
          case ORDER.RETMODIFY:
            this.chlList = [];
            this.title = "收费项目调整";
            this.$refs.dialog.open();
            await this.dataInfo(); //收费详情
            await this.getXialaData(); //获取收费项目下拉框数据  
            break;
          case ORDER.INFO:
            this.title = "收费详情";
             let data = {};
              apiBase.DoService(
                data, 
                apiBase.getApiAdress().Param.GetCheckoutReport,
                res => {
                  this.personality = res.data.content;
                  if(this.personality == '20'){
                    this.printName = "收费清单打印";
                  }else if(this.personality == '10'){
                    this.printName = "火化登记表打印";
                  }else{
                    this.iskh = false;
                    if(!this.iscopysfqd){this.printName = "收费清单打印";}
                  }
              });
            this.dataInfo(); // 收费详情
            this.$refs.info.open();
            break;
          case ORDER.RETAILINFO:  //零售详情
            this.title = "收费详情";
            this.printName = "零售清单打印";
            this.dataInfo(); // 收费详情
            this.$refs.info.open();
            break;
          case ORDER.CHECKOUT:
          case ORDER.RETCHECKOUT:
            this.chlList = [];
            this.title = "结账";
            if(type && type === '2'){
              this.ischeck1 = false;
              this.ischeck2 = true;
            }else if(type && type === '1'){
              this.ischeck1 = true;
              this.ischeck2 = false;
            }
            this.getPayment(); //获取付款方式
            this.dataInfo(); // 收费详情
            this.$refs.checkout.open();
            break;
          case '修改火化编号':
            this.title = '修改火化编号'
            this.$refs.num.open();
            this.dataInfo();
            break;
          default:
            break;
        }
      },
      //选择收费项目
      chaSelect(index) {
        let chl = this.chlList[index];
        let cha = this.getChaByID(chl.CHLCHAID);
        //初始化chl
        if (cha) {
          chl.CHALOGO = cha.CHALOGO;
          chl.CHLCHANAME = cha.CHANAME;
          chl.CHLAUNIT = cha.CHAAUNIT;
          chl.CHLMONEY = cha.CHAMONEY;
          chl.CHLNUM = 1;
          chl.CHLMOUNT = chl.CHLMONEY * chl.CHLNUM;
          chl.CHLREDUCTION = cha.CHAJMMONEY * chl.CHLNUM;
          chl.CHLDISCOUNT = cha.CHADISCOUNT * chl.CHLNUM;
          chl.CHLRECEIVED = chl.CHLMOUNT - chl.CHLREDUCTION - chl.CHLDISCOUNT;
          chl.CHAMODIFYJMMONEY = cha.CHAMODIFYJMMONEY;
        }
      },
      moneychang() {
        this.NullandB = false;
      },
      Jianmianchang(){
        this.NullandB = true;
      },
      chlreductionchange(index) {
        // this.NullandB = true;
        let chl = this.chlList[index];
        chl.CHLDISCOUNT = 0;
        chl.CHLREDUCTION = this.checkMoney(chl.CHLREDUCTION.toString());
        let cha = this.getChaByID(chl.CHLCHAID);
        if (cha) {
          //减免单价大于单价，减免单价取单价
          //该部分是获取减免单价的 CHAJMMONEY
          var CHAJMMONEY = cha.CHAJMMONEY;
          if (chl.CHLMONEY < cha.CHAJMMONEY) {
            CHAJMMONEY = chl.CHLMONEY; //获取减免单价
          }
          // console.log(66666);
          // console.log(this.regInfo.REGISKEYPOINT);
          //减免类型为疫情减免的时候，减免金额不在考虑减免限价的问题，减免金额最高可为应收金额
          if(this.regInfo.REGISKEYPOINT == 'D'){
            if(chl.CHLREDUCTION > chl.CHLMOUNT){ //如果输入的减免金额大于应收金额,减免金额取应收金额
              chl.CHLREDUCTION = chl.CHLMOUNT;
            }else{
              chl.CHLREDUCTION = chl.CHLREDUCTION;
            }
          }else{
            // CHLMOUNT 应收金额
            //减免金额大于减免限价，减免金额取限价    
            // var CHLREDUCTION = accMul(CHAJMMONEY, chl.CHLNUM); //算出减免金额
            if (cha.CHAJMHIMONEY !== 0 && chl.CHLREDUCTION > cha.CHAJMHIMONEY) {
              // 应收金额小于减免限价，减免金额取应收金额
              if(cha.CHAJMHIMONEY > chl.CHLMOUNT){
                chl.CHLREDUCTION = chl.CHLMOUNT;
              }else{
                chl.CHLREDUCTION = cha.CHAJMHIMONEY;
              }
            } else {
              // console.log( '减免金额' + chl.CHLREDUCTION);
              // console.log('应收金额'+chl.CHLMOUNT)
              if(chl.CHLREDUCTION > chl.CHLMOUNT){
                chl.CHLREDUCTION = chl.CHLMOUNT;
              }else{
                chl.CHLREDUCTION = chl.CHLREDUCTION;
              }
            }
          }

        }
      },
      reset(e) {
        if(e == false) return;
        this.chaList = [];
        if(this.OnlyQueryBusiness){
          this.allCharge.forEach(item => {
            if(item.CYPTYPE == 'B'){
              this.chaList.push(item);
            }
          });
        }else{
          this.chaList = JSON.parse(JSON.stringify(this.allCharge));
        }
      },
      //获取常用项
      getCommonItem() {
        let data = {
          Data: {
            "REGYITIQX": this.regInfo.REGYITIQX,
            "REGGHQX": this.regInfo.REGGHQX
          }
        };
        apiBase.DoService(data, apiBase.getApiAdress().CommonItem.Query, res => {
          let common = [];
          let CodeName;
          if(ORDER.IsreductionTypeNol === true){
             this.chlList = [];
            for(var i=0;i<this.pointType.length;i++){
              if(this.pointType[i].CodeValue === this.regInfo.REGISKEYPOINT){
                CodeName = this.pointType[i].CodeName;
              }
            }
            var copydata = res.data.content.OutData;
            for(var i=0;i<copydata.length;i++){
              if(copydata[i].CNOTYPE === CodeName){
                common.push(copydata[i]);
              }
            }
          }else if(ORDER.IsreductionTypeNol === false){
            common = res.data.content.OutData;
          }
          // *****************************************************************************
          common.forEach(item => {
            var isContain = this.chlList.some(chl => {
              return item.CNOCHAID === chl.CHLCHAID;
            });
            if (!isContain) {
              let chl = JSON.parse(JSON.stringify(this.chl));
              let cha = this.getChaByID(item.CNOCHAID);
              if (cha) {
                chl.CHALOGO = cha.CHALOGO;
                chl.CHLCHAID = cha.CHAID;
                chl.CHLCHANAME = cha.CHANAME;
                chl.CHLAUNIT = cha.CHAAUNIT;
                chl.CHLMONEY = cha.CHAMONEY;
                chl.CHLNUM = 1;
                chl.CHLMOUNT = chl.CHLMONEY * chl.CHLNUM;
                chl.CHLREDUCTION = cha.CHAJMMONEY * chl.CHLNUM;
                chl.CHLDISCOUNT = cha.CHADISCOUNT * chl.CHLNUM;
                chl.CHLRECEIVED =
                  chl.CHLMOUNT - chl.CHLREDUCTION - chl.CHLDISCOUNT;
                chl.CHAMODIFYJMMONEY = cha.CHAMODIFYJMMONEY;
              }
              this.chlList.push(chl);
            }
          });
          // *********************************************************************************
          this.chlList = this.chlList.filter(item => {
            return item.CHLCHAID && item.CHLCHAID.length > 0;
          });
          this.chlList.push(JSON.parse(JSON.stringify(this.chl)));
        });
      },
      async queryAllCharge(){
        return new Promise((resolve,reject)=>{
          let data = {
            Data: {
              REGISKEYPOINT: this.regInfo.REGISKEYPOINT
            }
          };
          apiBase.DoService(
            data,
            apiBase.getApiAdress().Checkout.GetAllCharge,
            res => {
              this.allCharge = res.data.content.OutData; //保存的是所有的收费项目
              resolve()
            }
          );
        })
      },
      //ID获取收费项目
      getChaByID(chaId) {
        for (let i in this.allCharge) {
          if (this.allCharge[i].CHAID === chaId) {
            return this.allCharge[i];
          }
        }
      },
      check(index) {   
        let chl = this.chlList[index];
        chl.CHLMONEY = this.checkMoney(chl.CHLMONEY.toString());
        chl.CHLNUM = this.checkNumber(chl.CHLNUM.toString());
        chl.CHLDISCOUNT = this.checkMoney(chl.CHLDISCOUNT.toString()); //优惠金额
        chl.CHLREDUCTION = this.checkNumber(chl.CHLREDUCTION.toString()); //减免金额
      },
      isCommon() {
        return this.order === ORDER.CHEMODIFY;
      },
      //只能输入正整数
      checkNumber(value) {
        value = value.replace(/\D/g, "").replace(/^0+(?=\d)/, "");
        if (value !== "") {
          if (value.substr(0, 1) === "0" && value.length === 2) {
            value = value.substr(1, value.length);
          }
        } else {
          value = 0;
        }
        return value;
      },
      //只能输入金额
      checkMoney(value) {
        //修复第一个字符是小数点 的情况.
        if (value !== "" && value.substr(0, 1) === ".") {
          value = "";
        }
        value = value.replace(/^0*(0\.|[1-9])/, "$1"); //解决 粘贴不生效
        value = value.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
        value = value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
        value = value
          .replace(".", "$#$")
          .replace(/\./g, "")
          .replace("$#$", ".");
        value = value.replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3"); //只能输入两个小数
        if (value.indexOf(".") < 0 && value !== "") {
          //以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
          if (value.substr(0, 1) === "0" && value.length === 2) {
            value = value.substr(1, value.length);
          }
        } else if (value === "") {
          value = 0;
        }
        return value;
      },
      //计算当前行CHL
      chlCompute(index) {
        let chl = this.chlList[index];
        chl.CHLREDUCTION = 0;//每次计算的时候先把减免金额清空，然后下面在再从新计算减免金额
        let cha = this.getChaByID(chl.CHLCHAID); 
        if (cha) {
          chl.CHLMOUNT = chl.CHLMONEY * chl.CHLNUM;
          if(chl.CHAMODIFYJMMONEY == "B"){ //是否允许修改减免单价
            if(chl.CHLREDUCTION == 0){ //减免金额
              if(chl.CHLMONEY < cha.CHAJMMONEY){
                chl.CHLREDUCTION = chl.CHLMONEY;
              }else{
                chl.CHLREDUCTION = cha.CHAJMMONEY;
              }
            }
          }else{
            chl.CHLREDUCTION = cha.CHAJMMONEY * chl.CHLNUM;
          }
          chl.CHLRECEIVED = chl.CHLMOUNT - chl.CHLREDUCTION - chl.CHLDISCOUNT;
        }
      },
      //自定义筛选
      chaFilter(val) {        // OnlyQueryBusiness
        if(this.OnlyQueryBusiness){
          this.allCharge.forEach(item => {
            if(item.CYPTYPE == 'B'){
              this.chaList.push(item);
            }
          });
        }else{
          this.chaList = JSON.parse(JSON.stringify(this.allCharge));
        }
        // this.chaList = JSON.parse(JSON.stringify(this.allCharge));
        if (val) {
          if (val.length > 0)
            this.chaList = this.allCharge.filter(item => {
              if(this.IsUseAccurateQuery){
                // 精确查询
                return(item.CHANAME == val || item.CHADM.toLowerCase() == val.toLowerCase())
              }else{
                return (
                  item.CHANAME.indexOf(val) > -1 || item.CHADM.toLowerCase().indexOf(val.toLowerCase()) > -1   //模糊查询
                );
              }
            });
        }else{
          this.chaList = this.chaList;
        }
      },
      modifyNum(){
        apiBase.DoService({
          REGCREPROVENO:this.regInfo.REGCREPROVENO,
          REGBUSNUM:this.regInfo.CHDREGNO
        }, apiBase.getApiAdress().Checkout.UpdateCreProveNo, res => {
          this.$message({
            type: "success",
            message: "修改成功!"
          })
          this.closeDialog()
        });
      },
      //提交
      submit(checkout = false) {
        switch (this.order) {
          case ORDER.ADD://新增
          case '续存':
            this.dataAdd(checkout);
            break;
          case ORDER.CHEMODIFY://收费项目调整
          case ORDER.RETMODIFY://零售项目调整
            this.dataModify(checkout);
            break;
          case ORDER.CHECKOUT://结账
          case ORDER.RETCHECKOUT://零售结账
            this.chdCheckout();
            break;
          case '修改火化编号': // 修改火化编号
            this.modifyNum();
            break;
          default:
            break;
        }
      },
      closeDialog() {
        switch (this.order) {
          case ORDER.ADD:
          case ORDER.CHEMODIFY:
          case ORDER.RETMODIFY:
            this.$refs.dialog.close();
            break;
          case ORDER.CHECKOUT:
          case ORDER.RETCHECKOUT:
            this.$refs.checkout.close();
            break;
          case ORDER.INFO:
            this.$refs.info.close();
            break;
          case ORDER.RETAILINFO:
            this.$refs.info.close();
            break;
          case "续存":    // 宁波续存按钮
            this.$refs.dialog.close();
            break;
          case "修改火化编号":
            this.$refs.num.close();
            break;
          default:
            break;
        }
      },
      refreshData() {
        this.$emit("refreshData");
      },
      openDialog() {
        if(this.isShow === 1){
            this.submit(false);
        }else if(this.isShow === 0){
          this.$confirm("是否直接进行结账?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
          .then(() => {
            this.submit(true);
          })
          .catch(() => {
            this.submit(false);
          });
        }
      },
      isshowGroups(){
        let data = {};
        apiBase.DoService(data, apiBase.getApiAdress().Param.GetIsShowDptname, res => {
          this.ISSHOWGROUP = res.data.content;
        });
      },
      iscopysfqds(){
        apiBase.DoService({},apiBase.getApiAdress().Param.GetNoconditionPrint,res => {
          this.iscopysfqd = res.data.content; 
        });
      },
      ChargeOnlyQueryBusiness(){
        apiBase.DoService({},apiBase.getApiAdress().Param.GetChargeOnlyQueryBusiness,res => {
          this.OnlyQueryBusiness = res.data.content; //个性化物品下拉   义乌下拉只有服务类，其他馆是全部数据
        });
      },
      GetIsUseAccurateQuery(){
        apiBase.DoService({},apiBase.getApiAdress().Param.GetIsUseAccurateQuery,res => {
          this.IsUseAccurateQuery = res.data.content;  //个性化是否结账中精确查找   义乌true 其他false
        });
      },
      async queryRtfByReliefType(){
        return new Promise((resolve)=>{
          apiBase.DoService({RTFRELIEFTYPE:this.regInfo.REGISKEYPOINT},apiBase.getApiAdress().PaidPriceLimit.QueryRtfByReliefType,res => {
            this.chackprice = res.data.content
            resolve()
          })
        })
      },
    },
    created() {
      let data = {};
      apiBase.DoService(data, apiBase.getApiAdress().Param.GetIsCheckOutShowBigCHDRECEIVED, res => {
        this.showclass = res.data.content;
      });
      apiBase.DoService(data, apiBase.getApiAdress().Param.GetIsDirectAccount, res => {
        this.isShow = res.data.content;
      });
      apiBase.DoService(data, apiBase.getApiAdress().Param.GetIsUsePre, res => {
        this.IsUsePre = res.data.content;
      });
      apiBase.DoService({},apiBase.getApiAdress().Param.GetIsreductionTypeNol,res => {
        ORDER.IsreductionTypeNol = res.data.content; 
      });
      apiBase.DoService({},apiBase.getApiAdress().Param.GetIsPricingSubtotal,res => {
        this.IsPricingSubtotal = res.data.content; //个性化调整收费项目的时候是否显示小计（义乌true）   义乌true 其他false
      });
      apiBase.DoService({},apiBase.getApiAdress().Param.GetIsGovernIptDisplay,res => {
        this.IsGovernIptDisplay = res.data.content; //个性化结账管理控制付款方式，发票抬头，税号是否显示   义乌不显示 其他显示
      });
      apiBase.DoService({},apiBase.getApiAdress().Param.GetIsUseRegistryAddress,res => {
        this.istryAddress = res.data.content; //个性化是否显示结账中的户籍地址   义乌true 其他false
      });
      apiBase.DoService({},apiBase.getApiAdress().Param.GetIsShowCheckTakeCorpseAddress,res => {
        this.IsShowCheckTakeCorpseAddress = res.data.content; //调整收费项目不显示接尸地点（嵊州）
      });
      apiBase.DoService({},apiBase.getApiAdress().Param.GetIsCheckoutDisplayPrintInvoice,res => {
        this.printInvoice = res.data.content; //个性化结账完成是否显示打印发票的按钮（临海true 其他false）
      });
      apiBase.DoService({},apiBase.getApiAdress().Param.GetIsCheckoutDisplayPrintReg,res => {
        this.DisplayPrintReg = res.data.content; //个性化结账完成是否显示打印火化登记单的按钮（临海true 其他false）
      });
      apiBase.DoService({},apiBase.getApiAdress().Param.GetIsModChl,res => {
        this.isModChl = res.data.content; // 是否可以修改其他来源收费（flase可修改，true 不可修改）
      });
      apiBase.DoService({},apiBase.getApiAdress().Param.GetIsUseNewApiByRetail,res => {
        this.isUseNewApiByRetail = res.data.content; //  零售收费编号查询逝者信息是否调用新接口(true 根据来源  false 不根据来源)
      });
    },
    //计算属性
    computed: {
      mountTotal() {
        let total = 0;
        for (let chl of this.chlList) {
          total = accAdd(total, chl.CHLMOUNT);
        }
        return total;
      },
      reductionTotal() {
        let total = 0;
        for (let chl of this.chlList) {
          total = accAdd(total, chl.CHLREDUCTION);
        }
        return total;
      },
      discountTotal() {
        let total = 0;
        for (let chl of this.chlList) {
          total = accAdd(total, chl.CHLDISCOUNT);
        }
        return total;
      },
      chlreceivedTotal() {
        let total = 0;
        for (let chl of this.chlList) {
          total = accAdd(total, chl.CHLRECEIVED);
        }
        return total;
      },
      isAdd() {
        return this.order === ORDER.ADD || this.order === ORDER.RETMODIFY || this.order === '续存';
      }
    },
    // CHLRECEIVED 应缴   CHLMOUNT  应收    CHLREDUCTION 减免
    watch: {
      chlList: {
        async handler(newValue, oldValue) {
          if(oldValue.length == 0){
            await Promise.all([this.queryRtfByReliefType(), this.queryAllCharge()])
          }
          for (let chl of this.chlList) {
            let cha = this.getChaByID(chl.CHLCHAID);
            let chackpriceItem = this.chackprice.filter((item)=>{
              return chl.CHLCHAID == item.RTFCHAID
            })
            if(chackpriceItem.length){
              var chlmount = accMul(chl.CHLMONEY, chl.CHLNUM);
              // 收费最高价 最低价
              if(cha.CHAHIPRICE>0 && chlmount > cha.CHAHIPRICE){
                chl.CHLMOUNT = cha.CHAHIPRICE
              }else if(cha.CHAPRICE>0 && chlmount < cha.CHAPRICE){
                chl.CHLMOUNT = cha.CHAPRICE
              }else{
                chl.CHLMOUNT = chlmount
              }
              if(chlmount<chackpriceItem[0].RTFSTARTAMOUNT){
                chl.CHLRECEIVED = chackpriceItem[0].RTFSTARTAMOUNT
                chl.CHLREDUCTION = chl.CHLMOUNT - chl.CHLRECEIVED
              }else if(chlmount>chackpriceItem[0].RTFHIGHESTAMOUNT){
                chl.CHLRECEIVED = chackpriceItem[0].RTFHIGHESTAMOUNT
                chl.CHLREDUCTION = chl.CHLMOUNT - chl.CHLRECEIVED
              }else{
                chl.CHLRECEIVED = chl.CHLMOUNT
                chl.CHLREDUCTION = chl.CHLMOUNT - chl.CHLRECEIVED
              }
              continue
            }
             
            if (cha) {
              if(chl.CHAMODIFYJMMONEY == "B" && this.NullandB == true){
                  var chlmount = accMul(chl.CHLMONEY, chl.CHLNUM); //乘法
                  // 收费最高价 最低价
                  if(cha.CHAHIPRICE>0 && chlmount > cha.CHAHIPRICE){
                    chl.CHLMOUNT = cha.CHAHIPRICE
                  }else if(cha.CHAPRICE>0 && chlmount < cha.CHAPRICE){
                    chl.CHLMOUNT = cha.CHAPRICE
                  }else{
                    chl.CHLMOUNT = chlmount
                  }
                  chl.CHLRECEIVED = Subtr(chl.CHLMOUNT, chl.CHLREDUCTION); //应收金额 - 减免金额 = 应缴金额
                  this.NullandB == false;
                }else{
                  //减免单价大于单价，减免单价取单价
                  var CHAJMMONEY = cha.CHAJMMONEY;
                  if (chl.CHLMONEY < cha.CHAJMMONEY) {
                    CHAJMMONEY = chl.CHLMONEY;
                  }
                  var chlmount = accMul(chl.CHLMONEY, chl.CHLNUM); //乘法
                  // 收费最高价 最低价
                  if(cha.CHAHIPRICE>0 && chlmount > cha.CHAHIPRICE){
                    chl.CHLMOUNT = cha.CHAHIPRICE
                  }else if(cha.CHAPRICE>0 && chlmount < cha.CHAPRICE){
                    chl.CHLMOUNT = cha.CHAPRICE
                  }else{
                    chl.CHLMOUNT = chlmount
                  }
                  //减免金额大于减免限价，减免金额取限价
                  var CHLREDUCTION = accMul(CHAJMMONEY, chl.CHLNUM);
                  // 如果不是奉化馆的执行下面的if代码
                  if (cha.CHAJMHIMONEY !== 0 && CHLREDUCTION > cha.CHAJMHIMONEY) {
                    chl.CHLREDUCTION = cha.CHAJMHIMONEY;
                  } else {
                    chl.CHLREDUCTION = CHLREDUCTION;
                  }

                  //优惠金额不能大于优惠限价
                  var CHLJMH = Subtr(chl.CHLMOUNT, chl.CHLREDUCTION);
                  var CHAHIDISCOUNT = cha.CHAHIDISCOUNT;
                  if (cha.CHAHIDISCOUNT !== 0) {
                    if (cha.CHAHIDISCOUNT > CHLJMH) {
                      CHAHIDISCOUNT = CHLJMH;
                    }
                  } else {
                    CHAHIDISCOUNT = CHLJMH;
                  }
                  if (chl.CHLDISCOUNT > CHAHIDISCOUNT) {
                    chl.CHLDISCOUNT = CHAHIDISCOUNT;
                  }
                  chl.CHLRECEIVED = Subtr(CHLJMH, chl.CHLDISCOUNT);
                }
              }
          }
        },
        deep: true
      },
    },
    mounted() {
      apiBase.DoService(
      {},
      apiBase.getApiAdress().Param.GetBackgroundColor,
      res => {
        let backcolor = '';
        if(res.data.content === '20'){
          const inputs = document.querySelectorAll('.backcolor input.el-input__inner');
          backcolor = 'rgb(255,255,153)'
          for(var i = 0; i< inputs.length; i++){
          inputs[i].style.backgroundColor = backcolor
          }
        }
      }
    );
    },
    components: {
      sweetModal,
      chargeChoose
    }
  };

</script>
